﻿using Microsoft.AspNetCore.Http;
using ShareCode.Entity.User;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Infrastructure.Model.User
{
    public class UserSessionInfoModel
    {
        public static UserSessionInfoModel? GetSession(IHttpContextAccessor httpContext)
        {

            if (httpContext == default) return default;

            if (httpContext.HttpContext == default || !httpContext.HttpContext.Items.ContainsKey(ConstantDefine.SESSION_KEY))
            {
                return default;
            }

            var obj = httpContext.HttpContext.Items[ConstantDefine.SESSION_KEY] as UserSessionInfoModel;

            return obj;
        }
        public long UserAccountId
        {
            get; set;
        }
        public long OrgId
        {
            get; set;
        }
        public List<long> DepartmentId { get; set; } = new List<long>();
        public List<long> WorkGroupId { get; set; } = new List<long>();
        public long ProjectId
        {
            get; set;
        }
        public long EntryInformationId
        {
            get; set;
        }

        public bool IsAdmin
        {
            get; set;
        }
        public bool IsOrgAdmin
        {
            get; set;
        }

        public List<int> Auths { get; set; } = new List<int>();

        public UserSessionInfoModel()
        {

        }
        public UserSessionInfoModel(UserAccountEntity? userInfo, UserEntryInformationEntity? entry, UserOrgEntity? org)
        {
            UserAccountId = userInfo?.Id??0;
            // EntryInformationId = userInfo.;


            if (entry != null)
            {
                OrgId = entry.OrgId;
                IsOrgAdmin = entry.IsAdmin == 1;
            }

            if (org != null)
            {
                IsAdmin = org.IsAdmin == 1;

            }
        }

    }
}
